***** RUN DO_MASTER.do ***** do "$Do_files\DO_MASTER.do"

global program "OA_TableB22"
cap log close
cap log using "$Results_log\log_$program$today", replace

**** REPLICATION OF TABLE B.2.2 ****

clear all
set mem 2g
set more off

// Import data

use $Data\data_two_steps_1 , clear

// Individual controls vector

global i_controls "age age2 i.sex_cd_p relation_* i.recidive_p"

// Esimations

reghdfe coverage_nat   Iiso* readershare	Ddist_min $i_controls, absorb(pk_wy pk_dow pk_commune newspaper type_crime) cluster(pk_case) 

egen max = max(id_iso)
global sup = max
foreach num of numlist 1/$sup {

	replace beta 	= _b[Iiso`num'] 				if Iiso`num'== 1
	replace se 		= _se[Iiso`num'] 				if Iiso`num'== 1

}

collapse (mean) beta* se* pk_DMUS90_p pk_DMUS50_p sh_mus_AS , by(id_iso iso_native_p)

sort iso_native_p

merge iso_native_p using $Data\data_two_steps_2
drop _merge

drop if se == 0 
gen weight_scheme = 1/se

reg beta DMUS_median  DHIN_median DJEW_median DBUD_median DCHR_median DOTH_median [aweight=weight_scheme], ro
estimates store est1
estadd scalar F_test=r(F)
estadd scalar p_value=r(p)
sum beta if e(sample)
estadd scalar mean=r(mean)

reg beta DMUS_median  DHIN_median DJEW_median DBUD_median DCHR_median DOTH_median circle1 circle2 AS BC [aweight=weight_scheme], ro 
estimates store est2
estadd scalar F_test=r(F)
estadd scalar p_value=r(p)
sum beta if e(sample)
estadd scalar mean=r(mean)

reg beta DMUS_median  DHIN_median DJEW_median DBUD_median DCHR_median DOTH_median circle1 circle2 AS BC ldist [aweight=weight_scheme], ro
estimates store est3
estadd scalar F_test=r(F)
estadd scalar p_value=r(p)
sum beta if e(sample)
estadd scalar mean=r(mean)

reg beta DMUS_median  DHIN_median DJEW_median DBUD_median DCHR_median DOTH_median circle1 circle2 AS BC s3un [aweight=weight_scheme], ro
estimates store est4
estadd scalar F_test=r(F)
estadd scalar p_value=r(p)
sum beta if e(sample)
estadd scalar mean=r(mean)

reg beta DMUS_median  DHIN_median DJEW_median DBUD_median DCHR_median DOTH_median circle1 circle2 AS BC lpop [aweight=weight_scheme], ro
estimates store est5
estadd scalar F_test=r(F)
estadd scalar p_value=r(p)
sum beta if e(sample)
estadd scalar mean=r(mean)

reg beta DMUS_median  DHIN_median DJEW_median DBUD_median DCHR_median DOTH_median circle1 circle2 AS BC lgle_cgdpc [aweight=weight_scheme], ro
estimates store est6
estadd scalar F_test=r(F)
estadd scalar p_value=r(p)
sum beta if e(sample)
estadd scalar mean=r(mean)

// Export Table
	
estout est1 est2 est3 est4 est5 est6 ///
using "$Results\\$program.tex", replace style(tex) type label	///
	cells(b(star fmt(%9.3f)) se(par fmt(%9.3f)))  ///
	stats(N r2_a mean, lab("Observations" "Adjusted $ R^2 $" "Sample Average") fmt(0 3 3)) ///  
	collabels(none) ///
	mlabels(, span none prefix(\multicolumn{@span}{c}{) suffix(})) ///
	msign(--) starlevels($^c$ .1 $^b$ .05 $^a$ .01) ///
	keep(DMUS_median  DHIN_median DJEW_median DBUD_median DCHR_median DOTH_median circle1 circle2 AS BC ldist s3un lpop lgle_cgdpc) /// 
	order(DMUS_median  DHIN_median DJEW_median DBUD_median DCHR_median DOTH_median circle1 circle2 AS BC ldist s3un lpop lgle_cgdpc) /// 
	title(Crime news provision: Perpetrators' origins) ///	
	prehead("\begin{table}[t!]" ///
	"\begin{center}" ///
	"\begin{threeparttable}" ///
	"\begin{footnotesize}" ///
	"\caption{\small{@title}\label{$program}}" ///
	"\begin{tabular*}{\columnwidth}{@{\extracolsep{\stretch{1}}}l*{@M}{c}@{}}" ///
	"\hline" "\hline" ///	
	"\\" ///
	"Dependent Variable		&\multicolumn{6}{c}{$\hat{\rho}_{n}$ (See Equation \ref{EQ_BIAS_country_step2})}\\" ///
	"\cmidrule{2-7}" ///
	"						&\multicolumn{1}{c}{(1)} &\multicolumn{1}{c}{(2)}  &\multicolumn{1}{c}{(3)}   &\multicolumn{1}{c}{(4)} &\multicolumn{1}{c}{(5)} &\multicolumn{1}{c}{(6)}\\") ///
	posthead("\hline" ///
	"\\") ///
	prefoot("\\" ///
	"\hline") ///
	postfoot("\hline" "\hline" ///
	"\end{tabular*}" /// 
	"\end{footnotesize}" ///
	"\begin{tablenotes}[normal,flushleft]" ///
	"\begin{scriptsize}" ///
	"\item \emph{Notes}:" /// 
	"GLS estimations." ///
	"The dependent variable consists of the estimated coefficients at the nationality level from the regression equation \ref{EQ_BIAS_country_step1}. " ///
	"Robust standard errors in parentheses. " ///
	"{$^c$} significant at 10\%; {$^b$} significant at 5\%; {$^a$} significant at 1\%. " /// 
	"" ///
	"\end{scriptsize}" ///
	"\end{tablenotes}" ///
	"\end{threeparttable}" ///
	"\end{center}" ///
	"\end{table}")

cap log close	
